from functools import reduce

from django.http import HttpResponse
from django.shortcuts import render
from datetime import datetime

# Create your views here.
def index(request):
    return render(request, "index.html")

def baidu(request):
    return render(request, "baidu.html")

def info(request):
    username = '知了课堂'
    book = {'name': "水浒传", 'auther': "施耐庵"}
    books = [{'name': "水浒传", 'auther': "施耐庵"},
            {'name': "三国演义", 'auther': "罗贯中"}
    ]

    class Person:
        def __init__(self, realname):
            self.realname = realname

    context = {
        'username': username,
        'book': book,
        'books': books,
        'person': Person("知了课堂")
    }
    return render(request, 'info.html', context=context)

def if_view(request):
    age = 20
    context = {
        'age': age,
    }
    return render(request, 'if.html', context=context)

def for_view(request):
    books = [
        # {'name': "水浒传", 'auther': "施耐庵"},
        # {'name': "三国演义", 'auther': "罗贯中"}
    ]
    person = {
        'realname': "知了课堂",
        "age": 18,
        "height": 100
    }
    context = {
        'books': books,
        'person': person
    }
    return render(request, 'for.html', context=context)

def with_view(request):
    context = {
        'books': [
            {'name': "水浒传", 'auther': "施耐庵"},
            {'name': "三国演义", 'auther': "罗贯中"}
        ]
    }
    return render(request, 'with.html', context=context)

def url_view(request):
    return render(request, 'url.html')

def book_detail(request, book_id):
    return HttpResponse(f'您访问的图书ID是：{book_id}')

def filter_view(request):
    greet = "Hello World, Hello Django"
    context = {
        'greet': greet,
        'birthday':datetime.now(),
        'profile': "",
        'html': "<h1>欢迎来到知了课堂</h1>"
    }
    return render(request, 'filter.html', context=context)

# def template_form(request):
#     context = {
#         'articles': ['小米su7', 'ChatGPT 5发布'],
#     }
#     return render(request, 'xfz_index.html', context=context)

def template_form(request):
    context = {
        'articles': ['小米su7', 'ChatGPT 5发布'],
    }
    return render(request, 'xfz_index.html', context=context)

def static_view(request):
    return render(request, 'static.html')